﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ProjectBase.Core;
using ProjectBase.Core.Service;
using ProjectBase.Mvc;

using $safeprojectname$.Restrictions;

namespace $safeprojectname$
{
    public static class ControlRenderManager
    {
        public static void Init()
        {
            ControlHtml.PreRenderControl += ControlHtml_OnPreRenderControl;

            // Init Handlers
            var handlers = Factory.CreateInstances<IControlRenderHandler>();
            foreach (var handler in handlers)
            {
                Instance.Provider.Add(handler.EntityType, handler);
            }
        }

        static void ControlHtml_OnPreRenderControl(object sender, PreRenderControlEventArgs args)
        {
            Instance.Provider.ControlHtml_OnPreRenderControl(sender as IVisualControl, args);
        }

        #region lazy instance

        // beforefieldinit off
        // see: http://www.yoda.arachsys.com/csharp/singleton.html
        // see: http://www.yoda.arachsys.com/csharp/beforefieldinit.html
        private static class Instance
        {
            // beforefieldinit
            public static readonly IControlRenderProvider Provider;

            static Instance()
            {
                Provider = Factory.CreateInstance<IControlRenderProvider>();
            }
        }

        #endregion lazy instance
    }
}
